package com.huan.wc;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//Map阶段
//KEYIN 输入数据的key (长度)
//VALUEIN 输入数据的value (值)
//KEYOUT 输出数据的key
//VALUEOUT 输出数据的Value类型
public class MyMapper extends Mapper<LongWritable, Text,Text, IntWritable> {

    Text k =  new Text();
    IntWritable v = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //TODO 获取一行一行数据
        String line = value.toString();
        //TODO 切割单词
        String[] splits = line.split( "," );

        //TODO 循环遍历 并写出
        for (String split : splits) {
            //TODO
            k.set( split );
            v.set( 1 );
            context.write( k,v );
        }
    }
}
